import 'package:flutter/material.dart';
import 'package:oli/shared/theme.dart';
import 'package:oli/viewmodel/text_view_model.dart';
import 'package:provider/provider.dart';

class NoCon extends StatefulWidget {
  static final String routeName = '/NoCon';

  @override
  _NoConState createState() => _NoConState();
}

class _NoConState extends State<NoCon> {
  TextEditingController text = new TextEditingController();

  bool _switchSelected = false;
  bool _checkboxSelected = false;

  @override
  Widget build(BuildContext context) {
    text.text = Provider.of<TextViewModel>(context).text;

    return Scaffold(
      body: Container(
        child: Column(
          children: <Widget>[
            Consumer<TextViewModel>(
              builder: (ctx, vm, child) {
                return TextField(
                  controller: text,
                  onChanged: (value) {
                    vm.text = value;
                  },
                );
              },
            ),
            NoText(),
            // 单选框
            Switch(
              // 当前状态
              value: _switchSelected,
              onChanged: (value){
                // 重新构建页面
                setState(() {
                  _switchSelected = value;
                });
              },
            ),

            // 复选框
            Checkbox(
              value: _checkboxSelected,
              onChanged: (value) {
                setState(() {
                  _checkboxSelected = value;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}

class NoText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String text = Provider.of<TextViewModel>(context).text;
    return Text(text);
  }
}

